﻿using System;
using System.IO;
using Newtonsoft.Json;
using Soundteller.Audio.Model;
using Soundteller.Audio.Repositories.Interfaces;

namespace Soundteller.Audio.Repositories
{
    public class StorageRepository : IStorageRepository
    {
        public T Load<T>(string filePath)
        {
            T result = default(T);

#if WINDOWS || XBOX
            using (var stream = File.OpenText(filePath))
            {
                result = JsonConvert.DeserializeObject<T>(stream.ReadToEnd());
            }
#endif

#if WINDOWS_PHONE
            //TODO: extract dependency for reading files
            var wp7Song = @"{""Id"":""118805f6-830d-4aca-93b9-0486e2924a2d"",""Bpm"":120.0,""EndBeat"":4.0,""Time"":""00:00:00"",""LoopEnabled"":true,""IsActive"":false,""Sounds"":[{""Id"":""fc057ff9-bd20-4d48-a6e7-278c1de8513a"",""Name"":""kick"",""Beat"":0.0,""IsBuffered"":false,""FilePath"":""kick.wav""},{""Id"":""5c95be3f-4ac0-4918-820e-568f811aa895"",""Name"":""clap"",""Beat"":2.0,""IsBuffered"":false,""FilePath"":""clap.wav""}]}";
            result = JsonConvert.DeserializeObject<T>(wp7Song);
#endif

            return result;
        }
    }
}